﻿using System;
using System.Reflection;
using System.Windows.Forms;

namespace HYCodeBase.WinForm.WinFormRemindSuit
{
	internal class GeneralReflectPropertySeter<X>
	{
		protected bool TrySetOneAttributeGeneral(ref System.Windows.Forms.Control inputControl, AttributeInformationBean inputAttribute, AppendTransform<X> inputAppendTransform = null)
		{
			bool result;
			try
			{
				PropertyInfo property = inputControl.GetType().GetProperty(inputAttribute.StrAttributeName);
				X x = this.GetValueOfString(inputAttribute.StrValueString);
				if (inputAppendTransform != null)
				{
					x = inputAppendTransform(inputControl, inputAttribute, x);
				}
				property.SetValue(inputControl, x);
				result = true;
			}
			catch (Exception)
			{
				result = false;
			}
			return result;
		}

		protected virtual X GetValueOfString(string inputStr)
		{
			return default(X);
		}
	}
}
